package stmlib;
import java.util.*;

/** 
 *  A transactional iterator. Can share a lock with underlying Container. Read-only by default.
 */
public class StmIterator<E> extends Lockable implements Iterator<E> {
    Iterator<E> source;
    public StmIterator(Iterator <E> source, LockManager lm) { this.lm = lm; this.source = source; }
    public boolean hasNext() { lm.readLock(); return source.hasNext(); }
    public E next() { lm.readLock(); return source.next(); }
    public void remove() { throw new UnsupportedOperationException(); }
    public StmIterator<E> lock() { lm.writeLock(); return this; }
}

